package com.hmdp.config;

import com.hmdp.utils.LoginInterceptor;
import com.hmdp.utils.RefreshTokenInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Override
    //登陆拦截器
    public void addInterceptors(InterceptorRegistry registry) {//添加拦截器
        registry.addInterceptor(new  LoginInterceptor())
                .excludePathPatterns("/user/login",
                                        "/user/code",
                                        "/blog/hot",
                                        "/shop/**",
                                        "/shop-type/**",
                                        "/upload/**",
                                        "voucher/** ")
                .order(1);//拦截器的注册器
        //order值越大，执行的顺序越靠后，默认为0
        //token刷新的拦截器
        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate)).addPathPatterns("/**").order(0);
    }
}
